<template>
  <div >
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" >
      <el-menu-item index="1" @click="getAuthorCollections">全部收藏</el-menu-item>
      <el-menu-item index="2" @click="getAuthorSpecialCollections">特别收藏</el-menu-item>
    </el-menu>
    <el-row type="flex"  justify="center" class="my_article_item" v-for="a in collectionList">
      <el-col :span="22" style="border: 1px solid lightgray;height: 180px;margin-top: 20px" class="my_article_body">
        <h3>{{a.title}}</h3>
        <div class="my_article_description">{{a.summary}}</div>
        <div class="my_article_bottom" style="margin-top: 10px">
          <i class="iconfont icon-yanjing" style="color: #5bc65b;">{{a.viewCount}}</i>
          <i class="iconfont icon-shoucang" style="color: #5bc65b;">{{a.collectionCount}}</i>
          <i class="iconfont icon-good" style="color: #5bc65b;">{{a.likeCount}}</i>
          <span class="article_detail" style="display:inline-block;margin-left:200px;color: #5bc65b" @click="showArticleDetail(a.id,a.user.id)">查看></span>
          <span class="article_detail" style="display:inline-block;margin-left:40px;color: #5bc65b">作者:{{a.user.nickname}}</span>
        </div>
      </el-col>
    </el-row>
    <div class="block" style="margin-left: 35%;margin-top: 30px;margin-bottom: 30px">
      <el-pagination
          background
          :hide-on-single-page="true"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "MyCollections",
  props:['authorId'],
  data(){
    return {
      activeIndex:'1',
      collectionList:[],
      currentPage:1,
      total:5,
      pageSize:5,
      isSpecial:''
    }
  },
  methods:{
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      if(this.isSpecial == 1){
        this.getAuthorSpecialCollections()
      }else{
        this.getAuthorCollections()
      }

    },
    getAuthorCollections(){
      this.isSpecial = '';
      let url = 'article/getCollectionArticleListByAuthorId'
      this.$axios.get(url,{
        params:{
          now:this.currentPage,
          size:this.pageSize,
          authorId:this.authorId,
        }

      }).then(res=>{
        if (res.data.code == 200){
          this.collectionList = res.data.data.list;
          this.currentPage = res.data.data.pageNum;
          this.total = res.data.data.total;
          this.pageSize = res.data.data.pageSize;
          console.log(res)
        }
      })

    },
    getAuthorSpecialCollections(){
      this.isSpecial = 1;
      let url = 'article/getCollectionArticleListByAuthorId'
      this.$axios.get(url,{
        params:{
          now:this.currentPage,
          size:this.pageSize,
          authorId:this.authorId,
          type:1
        }

      }).then(res=>{
        if (res.data.code == 200){
          this.collectionList = res.data.data.list;
          this.currentPage = res.data.data.pageNum;
          this.total = res.data.data.total;
          this.pageSize = res.data.data.pageSize;
          console.log(res)
        }
      })
    },
    showArticleDetail(articleId,authorId){
      this.$router.push({
        path:'/articleDetail',
        query: {
          articleId: articleId,
          authorId: authorId
        }
      });
    }

  },
  created() {
    this.getAuthorCollections(this.authorId)
  }
}
</script>

<style scoped>
.my_article_body{
  padding: 0 10px;
  border-radius: 4px;
}
.my_article_body h3{
  padding: 8px 20px;
  margin: 0;
  border-bottom: 1px solid lightgray;
}
.my_article_description {
  padding: 8px 20px;
  height: 80px;
  margin: 0;
}
.my_article_bottom {
  padding: 3px 20px;
  border-top: 1px solid lightgray;
  line-height: normal;
}
.my_article_bottom i:not(:first-child) {
  margin-left: 30px;
  width: 40px;
}
.article_detail:hover {
  /*text-underline:#5bc65b;*/
  text-decoration: underline;
  cursor: pointer;
  color: #f1da7f;;
}
</style>